//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口;

public class demo_2379 {
    public demo_2379() {
    }

    public static void main(String[] args) {
        System.out.println(minimumRecolors("WBBWWBBWBW", 7));
    }

    public static int minimumRecolors(String blocks, int k) {
        int left = 0;
        int count = 0;
        int min = Integer.MAX_VALUE;

        for(int i = 0; i < blocks.length(); ++i) {
            if (blocks.charAt(i) == 'W') {
                ++count;
            }

            if (i >= k - 1) {
                min = Math.min(min, count);
                if (min == 0) {
                    return 0;
                }

                if (blocks.charAt(left) == 'W') {
                    --count;
                }

                ++left;
            }
        }

        return min;
    }
}
